//
//  generalToolBox.h
//  XHYMall
//
//  Created by Assassin on 2019/6/28.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

//自定义NSlog
#ifdef DEBUG
#define DebugLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define DebugLog(...)
#endif

//屏幕高度
#define ScreenHeight [UIScreen mainScreen].bounds.size.height

//屏幕宽度
#define ScreenWidth  [UIScreen mainScreen].bounds.size.width

//控制器视图高度
#define ViewHeight self.view.bounds.size.height

//控制器视图宽度
#define ViewWidth  self.view.bounds.size.width

//iPhoneX / iPhoneXS
#define  isIphoneX_XS     (ScreenWidth == 375.f && ScreenHeight == 812.f ? YES : NO)

//iPhoneXR / iPhoneXSMax
#define  isIphoneXR_XSMax    (ScreenWidth == 414.f && ScreenHeight == 896.f ? YES : NO)

//是否是全面屏
#define   isBigScreen    (isIphoneX_XS || isIphoneXR_XSMax)

//状态栏高度
#define  StatusBarHeight     (isBigScreen ? 44.f : 20.f)

//导航栏菜单栏高度
#define  NavigationBarHeight  44.f

//标签栏高度
#define  TabbarHeight         (isBigScreen ? (49.f+34.f) : 49.f)

//标签栏安全区高度
#define  TabbarSafeBottomMargin         (isBigScreen ? 34.f : 0.f)

//导航栏和状态高度总和
#define  StatusBarAndNavigationBarHeight  (isBigScreen ? 88.f : 64.f)


/** APP名称 */
#define APP_NAME ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"])

/** 程序版本号 */
#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

/** APP build版本 */
#define APP_BUILD ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])

//手机型号
#define isiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define isiPhone5 (isiPhone && ScreenHeight == 568.0)
#define isiPhone6 (isiPhone && ScreenHeight == 667.0)
#define isiPhone6P (isiPhone && ScreenHeight == 736.0)
#define isiPhoneX (isiPhone && ScreenHeight == 812.0)
#define isiPhoneXr (isiPhone && ScreenHeight == 896.0)
#define isiPhoneXX (isiPhone && ScreenHeight > 811.0)

//RGB格式
#define RGB(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
//RGBA格式
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
//随机颜色
#define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

//加载图片
#define getImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
//弱引用
#define WeakSelf(type)  __weak typeof(type) weak##type = type
//强引用
#define StrongSelf(type)  __strong typeof(type) type = weak##type

/** 限制键盘输入内容 */
#define NUM @"0123456789"

#define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

//#define DEF_NUMBERCHARCHINA [generalToolBox specialSymbolsAction]

#define DEF_NUMBERCHARCHINA @"?'\%=:;~￥#&*<>《》()[]{}【】^@/￡¤|§¨「」『』￠￢￣（）——+|$_€¥？/|，,。!！"

@interface generalToolBox : NSObject

#pragma mark xib
//SB中创建VC
+ (UIViewController *) buildVcWithName:(NSString *)name AndId:(NSString *)idStr;

//从Xib中加载一个View
+ (UIView *)buildViewWithName:(NSString *)name AndIndex:(NSInteger)index;

//从Xib中加载一个cell
+ (UITableViewCell *)buildCellWithName:(NSString *)name AndIndex:(NSInteger)index;

//获取当前显示的控制器
+ (UIViewController *)getcurrentVC;

#pragma mark 正则表达式

//是否为正确的邮箱账号
+ (BOOL) isValidateEmail:(NSString *)email;

//是否为正确的电话号码
+ (BOOL) isValidatePhoneNum:(NSString *)mobile;

//是否为正确的身份证号码
+ (BOOL) isValidateIdentityCard: (NSString *)identityCard;

//密码强度
+(BOOL) weakOrStrongPwd:(NSString *)pwdStr;

//是否为正确的银行卡账号
+(BOOL) isValidCardNumber:(NSString *)cardNumber;

//是否为正确的护照号码
+ (BOOL) isValidPassport:(NSString*)value;

#pragma mark 颜色
//将十六进制颜色字符串转化为RGB颜色  colorStr:16进制字符串（可以以0x开头，可以以#开头，也可以就是6位的16进制）
+ (UIColor *)getColorWithHexadecimalColorStr:(NSString *)colorStr;

+ (UIColor *)getColorWithHexadecimalColorStr:(NSString *)colorStr andAlpha:(float)alpha;


#pragma mark 字符串

//获取字符串的宽度或高度
+ (CGSize)sizeForStr:(NSString *)str WithFont:(UIFont * _Nonnull)font maxSize:(CGSize)maxSize;

//是否包含另一个字符串
+ (BOOL)isInclucString:(NSString * _Nonnull)mainStr andSubString:(NSString *)subStr;

//从时间戳获取出nsdate字符串 ymdhms
+ (NSString *)getYMDHMSStringFromDateString:(NSString *)timeStampString;

//从时间戳获取出nsdate字符串 ymd
+ (NSString *)getYMDStringFromDateString:(NSString *)timeStampString;

+ (NSString *)timeStampConversion:(NSInteger)time;
+ (NSString*)getCurrentTimes;

/**
 @method 获取指定宽度width,Label的高度
 @param label 待计算的Label
 @result float 返回的高度
 */
+ (float) getHeightForLabelString:(UILabel *)label andWidth:(float)width;

//获取字符串的宽度
+ (CGFloat)getWidthWithText:(NSString *)text height:(CGFloat)height font:(CGFloat)font;

//获取字符串的高度
+ (CGFloat)getHeightWithText:(NSString *)text width:(CGFloat)width font:(CGFloat)font;

//删除字符串的空格
+ (NSString *) removeWhiteSpaceWithStr:(NSString *)str;

//是否为空
+(BOOL) isEmptyString:(NSString *)string;

//是否为纯数字
+(BOOL)isNumberString:(NSString *)str;

//是否包含表情
+ (BOOL) stringContainsEmoji:(NSString *)string;

//去除字符串中的表情
+ (NSString *) converStrEmoji:(NSString *)emojiStr;

//是否是纯汉字字符串
+ (BOOL) isPureChineseCharacters:(NSString *)Str;

/// 特殊符号
+ (NSString *)specialSymbolsAction;

//去除字符串尾部的零
+(NSString *)removeAllZero:(NSString *)numberStr;

//获取一段字体颜色不一样的富文本
+ (NSMutableAttributedString *)getHighlightAttributeString:(NSString *)text highlightText:(NSString *)highlightText highlightColor:(NSString *)highlightColor;
#pragma mark 视图

+(void)cutTheRoundedForView:(UIView *)view withCornerRadius:(float)radius;

+(void)setBorderForView:(UIView *)view withBorderWidth:(float)width  withBorderColor:(NSString *)colorStr  withCornerRadius:(float)radius;

+(void)setVcViewAlpha:(UIViewController *)vc withAlpha:(float)alpha;

+ (UIImage *)getScreenShotForView:(UIView *)view withRect:(CGRect)rect;

+ (UIImage *)createQrImageWithInfoString:(NSString*)str;

+ (UIImage *) imageToTransparent:(UIImage*) image;

//设置状态栏背景色
+ (void)setStatusBarBackgroundColor:(UIColor *)color;

+ (void)cutWithView:(UIView *)view topLeftRounded:(CGFloat)topLeftRounded topRightRounded:(CGFloat)topRightRounded bottomRightRounded:(CGFloat)bottomRightRounded bottomLeftRounded:(CGFloat)bottomLeftRounded;

#pragma mark 时间
+ (NSString *)timeDifferenceWithStartTime:(NSString *)startTime endTime:(NSString *)endTime;

+ (NSString *)timeDifferenceWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate;

+ (NSString *)timeDifferenceNowWithTargetTime:(NSString *)targetTime;

+ (NSDate *)getNowDate;


@end

NS_ASSUME_NONNULL_END
